package com.xul.crowd.controller;

import com.xul.crowd.entity.Admin;
import com.xul.crowd.entity.Student;
import com.xul.crowd.service.AdminService;
import com.xul.crowd.util.CrowdUtil;
import com.xul.crowd.util.ResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author xul
 * @create 2021-07-22 19:55
 */

@Controller
public class TestController {

    @Autowired
    private AdminService adminService;

    @RequestMapping("test/ssm.html")
    public String testSsm(ModelMap modelMap, HttpServletRequest request) {
        List<Admin> adminList = adminService.findAll();
        modelMap.addAttribute("adminList", adminList);
        boolean type = CrowdUtil.judgeRequestType(request);
        System.out.println("type=" + type);
        String a= null;
        System.out.println(a.length());
        return "target";
    }

    @ResponseBody
    @RequestMapping("send/array.html")
    public String testReceiveArrayOne(@RequestParam("array[]") List<Integer> array) {
        for (Integer integer : array) {
            System.out.println("integer=" + integer);
        }
        // 字符串响应体
        return "Success";
    }

    @ResponseBody
    @RequestMapping("send/array.html/one.html")
    public String testReceiveArrayTwo(@RequestBody List<Integer> array) {
        Logger logger = LoggerFactory.getLogger(TestController.class);
        for (Integer integer : array) {
            logger.info("integer=" + integer);
            String a = null;
            System.out.println(a.length());
        }
        return "Success";
    }

    @ResponseBody
    @RequestMapping("send/compose/object.json")
    public ResultEntity<Student> test(@RequestBody Student student,HttpServletRequest request) {
        boolean type = CrowdUtil.judgeRequestType(request);
        System.out.println("type=" + type);
        String a= null;
        System.out.println(a.length());

        System.out.println(student.toString());
        return ResultEntity.successWithData(student);
    }


}
